<?php

namespace app\common\model;

use think\Model;

class Currency extends Model
{
    protected $table = 'currency';

    /**
     * 汇率信息
     * $currency = model('Currency')->getCurrency('USD');
        if ($currency['code'] == 200) {
            echo 1 / $currency['data'];
        }
     * @param  [type] $to_currency   [description]
     * @param  string $from_currency [description]
     * @return [type]                [description]
     */
    public function getCurrency($to_currency, $from_currency = 'CNY')
    {
    	$currency = $this->where(['to_currency' => $to_currency, 'from_currency' => $from_currency])->order(['date'=>'desc', 'time'=>'desc'])->value('currency');
    	return $currency ? $currency : false;
    	
    }
}
